package com.TrainingCenter.dao.impl;

import com.TrainingCenter.dao.Dao;
import com.TrainingCenter.entity.Persitent;
import com.TrainingCenter.entity.User;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ibook
 * Date: 07.05.14
 * Time: 13:34
 * To change this template use File | Settings | File Templates.
 */
public class UserDaoImpl extends AbstractHibernateDao<User> {


        @Override
    public void add(User persitent) {
        getSession().save(persitent);
    }

    @Override
    public void edit(User Persitent) {
        getSession().update(Persitent);
    }

    @SuppressWarnings("JpaQlInspection")
    @Override
    public void delete(int id) {
        Query query = getSession().createQuery("delete from user where id_user=:id_user");
         query.setInteger("id_user",id)   ;
        query.executeUpdate();
    }

    @Override
    public void delete(User Persitent) {
        getSession().delete(Persitent);
    }

    @Override
    public User get(int id) {
        return (User) getSession().load(User.class,id);
    }

    @SuppressWarnings("JpaQlInspection")
    @Override
    public List<User> getAllUser() {
    return getSession().createQuery("from User").list();  //To change body of implemented methods use File | Settings | File Templates.
    }
}
